# -*- coding: utf-8 -*-
# @Time : 2019/1/11 9:27
# @Author : Administrator
# @File : employment.py
# @Project : python
# @title : 接口测试 -- 财务管理
import unittest,ddt,re,random
from woniuboss_interface.util.read_data import Read_Excel
from woniuboss_interface.common.login_decode import Login

excel=Read_Excel()
session,host,excel_path = Login()
@ddt.ddt
class Turnover(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        query=session.post(url=host+"/finance/financeSelectSome",
                         data={"pageSize":"15","pageIndex":"1","subject_1":"主营业务收入",
                               "subject_2":"就业培训","selectTimeStart":"2019-01-01","selectTimeEnd":"2019-01-31"})
        text=query.text
        list=re.findall(r'"detailed_id":(.*?),',text,re.M)
        max=len(list)
        try:
            cls.did=list[random.randrange(0,max)]
        except:
            print("---没有操作对象，请预埋数据---")
        print('start')

    @classmethod
    def tearDownClass(cls):
        print('stop')

    @ddt.data(*excel.excel(excel_path,7))
    def testAdd(self,data):   #新增流水
        result=session.post(url=host+"/finance/addNewRecord",
                       data={ "deal.detailed_id":data['deal.detailed_id'],"deal.first_subject_id":data['deal.first_subject_id'],"deal.second_subject_id":data['deal.second_subject_id'],"deal.dealings_subject":data['deal.dealings_subject'],
                             "deal.dealings_subject1":data['deal.dealings_subject1'],"deal.trading_time":data['deal.trading_time'],"deal.person_in_charge":data['deal.person_in_charge'],
                             "income_and_expenses":data['income_and_expenses'],"deal.money_no":data['deal.money_no'],"deal.trading_account":data['deal.trading_account'],
                             "deal.counterparty":data['deal.counterparty'],"deal.detail_record":data['deal.detail_record']})
        text=result.text
        self.assertIn("success",text)

    @ddt.data(*excel.excel(excel_path,8))
    def testRevise(self,data):   #修改流水
        result=session.post(url=host+"/finance/updateFinance",
                       data={ "deal.detailed_id":self.did,"deal.first_subject_id":data['deal.first_subject_id'],"deal.second_subject_id":data['deal.second_subject_id'],"deal.dealings_subject":data['deal.dealings_subject'],
                             "deal.dealings_subject1":data['deal.dealings_subject1'],"deal.trading_time":data['deal.trading_time'],"deal.person_in_charge":data['deal.person_in_charge'],
                             "income_and_expenses":data['income_and_expenses'],"deal.money_no":data['deal.money_no'],"deal.trading_account":data['deal.trading_account'],
                             "deal.counterparty":data['deal.counterparty'],"deal.detail_record":data['deal.detail_record']})
        text=result.text
        self.assertIn("成功",text)

if __name__ == '__main__':
    unittest.main()